package org.example;

public class HotelService {
    // 预订房间
    public boolean bookRoom(int guestId, int roomId, LocalDate checkIn) {
        Connection conn = null;
        try {
            conn = DBUtil.getConnection();
            conn.setAutoCommit(false);

            // 1. 检查房间状态
            String checkSql = "SELECT is_available FROM rooms WHERE room_id = ?";
            // ...执行检查

            // 2. 更新房间状态
            String updateSql = "UPDATE rooms SET is_available = false WHERE room_id = ?";
            // ...执行更新

            // 3. 创建预订记录
            String insertSql = "INSERT INTO reservations (guest_id, room_id, check_in) VALUES (?, ?, ?)";
            // ...执行插入

            conn.commit();
            return true;
        } catch (SQLException e) {
            try {
                conn.rollback();
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
            return false;
        } finally {
            DBUtil.close(conn, null, null);
        }
    }
}
